package com.java110.mall.cart.api;

import com.alibaba.fastjson.JSONObject;
import com.java110.core.context.Environment;
import com.java110.mall.cart.bmo.housekeepingFeeConfig.IDeleteHousekeepingFeeConfigBMO;
import com.java110.mall.cart.bmo.housekeepingFeeConfig.IGetHousekeepingFeeConfigBMO;
import com.java110.mall.cart.bmo.housekeepingFeeConfig.ISaveHousekeepingFeeConfigBMO;
import com.java110.mall.cart.bmo.housekeepingFeeConfig.IUpdateHousekeepingFeeConfigBMO;
import com.java110.dto.housekeeping.HousekeepingFeeConfigDto;
import com.java110.dto.housekeeping.HousekeepingServFeeDto;
import com.java110.po.housekeeping.HousekeepingFeeConfigPo;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/housekeepingFeeConfig")
public class HousekeepingFeeConfigApi {

    @Autowired
    private ISaveHousekeepingFeeConfigBMO saveHousekeepingFeeConfigBMOImpl;
    @Autowired
    private IUpdateHousekeepingFeeConfigBMO updateHousekeepingFeeConfigBMOImpl;
    @Autowired
    private IDeleteHousekeepingFeeConfigBMO deleteHousekeepingFeeConfigBMOImpl;

    @Autowired
    private IGetHousekeepingFeeConfigBMO getHousekeepingFeeConfigBMOImpl;

    /**
     * 微信保存消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /housekeepingFeeConfig/saveHousekeepingFeeConfig
     * @path /app/housekeepingFeeConfig/saveHousekeepingFeeConfig
     */
    @RequestMapping(value = "/saveHousekeepingFeeConfig", method = RequestMethod.POST)
    public ResponseEntity<String> saveHousekeepingFeeConfig(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "feeName", "请求报文中未包含feeName");
        Assert.hasKeyAndValue(reqJson, "feeTypeCd", "请求报文中未包含feeTypeCd");
        Assert.hasKeyAndValue(reqJson, "computingFormula", "请求报文中未包含computingFormula");
        Assert.hasKeyAndValue(reqJson, "startTime", "请求报文中未包含startTime");
        Assert.hasKeyAndValue(reqJson, "endTime", "请求报文中未包含endTime");
        Assert.hasKeyAndValue(reqJson, "isDefault", "请求报文中未包含isDefault");


        HousekeepingFeeConfigPo housekeepingFeeConfigPo = BeanConvertUtil.covertBean(reqJson, HousekeepingFeeConfigPo.class);
        return saveHousekeepingFeeConfigBMOImpl.save(housekeepingFeeConfigPo);
    }

    /**
     * 微信修改消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /housekeepingFeeConfig/updateHousekeepingFeeConfig
     * @path /app/housekeepingFeeConfig/updateHousekeepingFeeConfig
     */
    @RequestMapping(value = "/updateHousekeepingFeeConfig", method = RequestMethod.POST)
    public ResponseEntity<String> updateHousekeepingFeeConfig(@RequestBody JSONObject reqJson) {
        Environment.isDevEnv();
        Assert.hasKeyAndValue(reqJson, "feeName", "请求报文中未包含feeName");
        Assert.hasKeyAndValue(reqJson, "feeTypeCd", "请求报文中未包含feeTypeCd");
        Assert.hasKeyAndValue(reqJson, "computingFormula", "请求报文中未包含computingFormula");
        Assert.hasKeyAndValue(reqJson, "startTime", "请求报文中未包含startTime");
        Assert.hasKeyAndValue(reqJson, "endTime", "请求报文中未包含endTime");
        Assert.hasKeyAndValue(reqJson, "isDefault", "请求报文中未包含isDefault");
        Assert.hasKeyAndValue(reqJson, "configId", "configId不能为空");


        HousekeepingFeeConfigPo housekeepingFeeConfigPo = BeanConvertUtil.covertBean(reqJson, HousekeepingFeeConfigPo.class);
        return updateHousekeepingFeeConfigBMOImpl.update(housekeepingFeeConfigPo);
    }

    /**
     * 微信删除消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /housekeepingFeeConfig/deleteHousekeepingFeeConfig
     * @path /app/housekeepingFeeConfig/deleteHousekeepingFeeConfig
     */
    @RequestMapping(value = "/deleteHousekeepingFeeConfig", method = RequestMethod.POST)
    public ResponseEntity<String> deleteHousekeepingFeeConfig(@RequestBody JSONObject reqJson) {
        Environment.isDevEnv();

        Assert.hasKeyAndValue(reqJson, "shopId", "商铺不能为空");

        Assert.hasKeyAndValue(reqJson, "configId", "configId不能为空");


        HousekeepingFeeConfigPo housekeepingFeeConfigPo = BeanConvertUtil.covertBean(reqJson, HousekeepingFeeConfigPo.class);
        return deleteHousekeepingFeeConfigBMOImpl.delete(housekeepingFeeConfigPo);
    }

    /**
     * 微信删除消息模板
     *
     * @param shopId 商铺ID
     * @return
     * @serviceCode /housekeepingFeeConfig/queryHousekeepingFeeConfig
     * @path /app/housekeepingFeeConfig/queryHousekeepingFeeConfig
     */
    @RequestMapping(value = "/queryHousekeepingFeeConfig", method = RequestMethod.GET)
    public ResponseEntity<String> queryHousekeepingFeeConfig(@RequestParam(value = "shopId", required = false) String shopId,
                                                             @RequestParam(value = "configId", required = false) String configId,
                                                             @RequestParam(value = "feeTypeCd", required = false) String feeTypeCd,
                                                             @RequestParam(value = "feeName", required = false) String feeName,
                                                             @RequestParam(value = "isDefault", required = false) String isDefault,
                                                             @RequestParam(value = "page") int page,
                                                             @RequestParam(value = "row") int row) {
        HousekeepingFeeConfigDto housekeepingFeeConfigDto = new HousekeepingFeeConfigDto();
        housekeepingFeeConfigDto.setPage(page);
        housekeepingFeeConfigDto.setRow(row);
        housekeepingFeeConfigDto.setShopId(shopId);
        housekeepingFeeConfigDto.setConfigId(configId);
        housekeepingFeeConfigDto.setFeeTypeCd(feeTypeCd);
        housekeepingFeeConfigDto.setFeeName(feeName);
        housekeepingFeeConfigDto.setIsDefault(isDefault);
        return getHousekeepingFeeConfigBMOImpl.get(housekeepingFeeConfigDto);
    }

    /**
     * 微信删除消息模板
     *
     * @param shopId 商铺IDqueryShopCommunity
     * @return
     * @serviceCode /housekeepingFeeConfig/queryHousekeepingServConfig
     * @path /app/housekeepingFeeConfig/queryHousekeepingServFeeConfig
     */
    @RequestMapping(value = "/queryHousekeepingServConfig", method = RequestMethod.GET)
    public ResponseEntity<String> queryHousekeepingServConfig(@RequestParam(value = "shopId", required = false) String shopId,
                                                              @RequestParam(value = "servId", required = false) String servId,
                                                              @RequestParam(value = "page") int page,
                                                              @RequestParam(value = "row") int row) {

        HousekeepingServFeeDto housekeepingServFeeDto = new HousekeepingServFeeDto();
        housekeepingServFeeDto.setPage(page);
        housekeepingServFeeDto.setRow(row);
        housekeepingServFeeDto.setServId(servId);
        housekeepingServFeeDto.setShopId(shopId);


        return getHousekeepingFeeConfigBMOImpl.getServFee(housekeepingServFeeDto);
    }


    /**
     * 微信删除消息模板
     *
     * @param shopId 商铺ID
     * @return
     * @serviceCode /housekeepingFeeConfig/queryServFeeConfig
     * @path /app/housekeepingFeeConfig/queryServFeeConfig
     */
    @RequestMapping(value = "/queryServFeeConfig", method = RequestMethod.GET)
    public ResponseEntity<String> queryHousekeepingServFeeConfig(@RequestParam(value = "shopId", required = false) String shopId,
                                                                 @RequestParam(value = "servId", required = false) String servId,
                                                                 @RequestParam(value = "isShow", required = false) String isShow,
                                                                 @RequestParam(value = "isDefault", required = false) String isDefault,
                                                                 @RequestParam(value = "page") int page,
                                                                 @RequestParam(value = "row") int row) {

        HousekeepingServFeeDto housekeepingServFeeDto = new HousekeepingServFeeDto();
        housekeepingServFeeDto.setPage(page);
        housekeepingServFeeDto.setRow(row);
        housekeepingServFeeDto.setShopId(shopId);
        housekeepingServFeeDto.setServId(servId);
        housekeepingServFeeDto.setIsShow(isShow);
        housekeepingServFeeDto.setIsDefault(isDefault);
        return getHousekeepingFeeConfigBMOImpl.getServFeeConfig(housekeepingServFeeDto);
    }
}
